package bb.lanxing.util.text;

import static android.content.Context.CLIPBOARD_SERVICE;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;

public class TextUtils {
    public static Spanned toHtmlLink(String str, String str2, int i, int i2) {
        return Html.fromHtml("<a href='" + str2 + "'style='text-decoration: none;'>" + str + "</a>");
    }

    public static boolean isEmptyOrNull(CharSequence charSequence) {
        return android.text.TextUtils.isEmpty(charSequence);
    }

    public static CharSequence formatSize(CharSequence charSequence, int i, int i2, int i3) {
        SpannableStringBuilder spannableStringBuilder = charSequence instanceof SpannableStringBuilder ? (SpannableStringBuilder) charSequence :
                new SpannableStringBuilder(charSequence);
        spannableStringBuilder.setSpan(new AbsoluteSizeSpan(i), i2, i3 + i2, 33);
        return spannableStringBuilder;
    }

    public static CharSequence formatColor(CharSequence charSequence, int i, int i2, int i3) {
        SpannableStringBuilder spannableStringBuilder = charSequence instanceof SpannableStringBuilder ? (SpannableStringBuilder) charSequence :
                new SpannableStringBuilder(charSequence);
        spannableStringBuilder.setSpan(new ForegroundColorSpan(i), i2, i3 + i2, 33);
        return spannableStringBuilder;
    }

    public static CharSequence formatColorAndSize(CharSequence charSequence, int i, int i2, int i3, int i4) {
        return formatSize(formatColor(charSequence, i, i3, i4), i2, i3, i4);
    }

    public static String getLimitString(String str, int i) {
        if (str == null || str.length() < i) {
            return str;
        }
        return str.substring(0, i) + "…";
    }

    public static boolean copyTextToClipBoard(Context context, CharSequence charSequence) {
        if (android.text.TextUtils.isEmpty(charSequence)) {
            return false;
        }
        ((ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText(null, charSequence));
        return true;
    }
}
